<template>
  <div class="exam-examrules-page">
    <nav-bar title="在线考试" theme="blue" message></nav-bar>
    <div class="page-main" style="margin-top: 44px">
      <div class="exam-examrules">
        <div class="exam-examrules-title">考试规则</div>
        <div class="exam-examrules-content">
          {{ $route.params.examRule }}
        </div>
        <div class="exam-examrules-footer">
          <van-button type="info" @click="onStart">开始考试</van-button>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  name: 'learnTest-exam-rules',
  data() {
    return {
      examRule: ''
    }
  },
  created() {
    if (!this.$route.params.code) this.$router.go(-1)
  },
  methods: {
    onStart() {
      const nowTimestamp = new Date().getTime()
      const startTimestamp = new Date(this.$route.params.startTime).getTime()
      const endTimestamp = new Date(this.$route.params.endTime).getTime()
      if (startTimestamp && nowTimestamp < startTimestamp) {
        this.$toast('考试尚未开始~')
      } else if (endTimestamp && nowTimestamp > endTimestamp) {
        this.$toast('考试已结束~')
      } else {
        if (this.$route.params.myExamCode) {
          this.$toast('您已答过该试卷~')
        } else {
          this.$router.push(`/learnTest/exam/start?code=${this.$route.params.code}`)
        }
      }
    }
  }
}
</script>
<style lang="less" scoped>
@import '~@/assets/style/learnTest/exam/rules.less';
</style>
